package com.sky.controller.user;


import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {

    private static final Logger log = LoggerFactory.getLogger(SetmealController.class);
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐数据
     * @return
     */
    @ApiOperation("根据分类id查询套餐数据")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> getByCategoryId(Long categoryId)
    {
        log.info("根据分类id查询套餐数据{}",categoryId);
        List<Setmeal> setmealList = setmealService.getByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询菜品
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品")
    public Result<List<DishItemVO>> getDishBySetmealId(@PathVariable Long id){
        List<DishItemVO> dishItemVOS = setmealService.getDishBySetmealId(id);
        return Result.success(dishItemVOS);
    }


}
